package com.biscuit.page.basicservice.conf.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.biscuit.page.basicservice.bean.AlipayConfigurationProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author biscuit
 * @create 2024年08月05日 14:35
 */
@Getter
@Setter
@Configuration
public class AlipayConfig {

    @Resource
    private AlipayConfigurationProperties configurationProperties;

    @PostConstruct
    public void init() {
        // 初始化 Alipay websocket 连接
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openchannel-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = configurationProperties.getAppId();
        config.merchantPrivateKey = this.configurationProperties.getAppPrivateKey();
        config.alipayPublicKey = this.configurationProperties.getAlipayPublicKey();
        config.notifyUrl = this.configurationProperties.getNotifyUrl();
        Factory.setOptions(config);
    }

}
